// /////////////////////////////////////////////////////////////////////////////
//
// Name:            asAssetProcessor.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Binds the AssetProcessor class to AngelScript
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __ASASSETPROCESSOR_H__
#define __ASASSETPROCESSOR_H__

// Include files
#include "../../dependencies.h"

#ifdef __COMPILE_WITH_ANGELSCRIPT__

#include "../../core/AssetProcessor.h"
#include "../ScriptHelper.h"


//! Binds the AssetProcessor class to AngelScript.
extern void bindAssetProcessor(asIScriptEngine *engine);

//! Binds the base behaviours and methods of the AssetProcessor to the given class in
//! AngelScript.
template<typename T>
void bindAssetProcessorBase(asIScriptEngine *engine, const char *type)
{
    // Forward declaration.
    int r;
    std::string sType = type;

    // Set common behaviour.
    r = engine->RegisterObjectBehaviour(type, asBEHAVE_ADDREF, "void f()",
                                        asMETHOD(T, grab), asCALL_THISCALL); assert(r >= 0);
    r = engine->RegisterObjectBehaviour(type, asBEHAVE_RELEASE, "void f()",
                                        asMETHOD(T, drop), asCALL_THISCALL); assert(r >= 0);

	r = engine->RegisterObjectBehaviour("AssetProcessor", asBEHAVE_REF_CAST, std::string(sType + "@ f()").c_str(),
                                        asFUNCTION((asRefCast<AssetProcessor,T>)), asCALL_CDECL_OBJLAST); assert( r >= 0 );

    r = engine->RegisterObjectBehaviour(type, asBEHAVE_IMPLICIT_REF_CAST, std::string("AssetProcessor@ f()").c_str(),
                                        asFUNCTION((asRefCast<T,AssetProcessor>)), asCALL_CDECL_OBJLAST); assert( r >= 0 );

    // Bind common class functions.
    r = engine->RegisterObjectMethod(type, "const string& getBaseName()",
                                     asMETHOD(T, getBaseName), asCALL_THISCALL); assert(r >= 0);
    r = engine->RegisterObjectMethod(type, "AssetGroup@ getParent()",
                                     asMETHOD(T, getParent), asCALL_THISCALL); assert(r >= 0);

    r = engine->RegisterObjectMethod(type, "bool reloadAsset(const string &in)",
                                     asMETHOD(T, reloadAsset), asCALL_THISCALL); assert(r >= 0);
    r = engine->RegisterObjectMethod(type, "void reloadAssets()",
                                     asMETHOD(T, reloadAssets), asCALL_THISCALL); assert(r >= 0);

    r = engine->RegisterObjectMethod(type, "bool removeAsset(const string &in)",
                                     asMETHOD(T, removeAsset), asCALL_THISCALL); assert(r >= 0);
    r = engine->RegisterObjectMethod(type, "void removeAssets()",
                                     asMETHOD(T, removeAssets), asCALL_THISCALL); assert(r >= 0);
}

#endif // __COMPILE_WITH_ANGELSCRIPT__

#endif
